package com.demo3.component;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class BeanLifeComponent implements BeanNameAware {

    //执行各种通知
    @Override
    public void setBeanName(String s) {
        System.out.println("执行了通知");
    }

    //初始化的前置和后置方法不能写在这个Bean中！

    //执行初始化方法(注解)
    @PostConstruct
    public void postConstruct() {
        System.out.println("通过注解 @PostConstruct 执行了初始化方法");
    }

    //使用
    public void useBean() {
        System.out.println("使用Bean");
    }

    //销毁
    @PreDestroy
    public void preDestory() {
        System.out.println("执行了销毁方法");
    }

}
